package com.whmnx.login.ui;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.whmnx.base.router.RouterActivityPath;
import com.whmnx.login.BR;
import com.whmnx.login.R;
import com.whmnx.login.databinding.ActivityLoginBinding;
import com.whmnx.login.ui.model.LoginViewModel;

import me.goldze.mvvmhabit.base.BaseActivity;

/**
 * author : huang
 * date   : 2020/9/16 0016 17:26
 * version: 1.0
 * @author Administrator
 */
@Route(path = RouterActivityPath.Sign.PAGER_LOGIN)
public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewModel> {

    public  Activity activity;
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_login;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        activity = this;
        viewModel.initData(this,binding);
       /* if (SPUtils.getInstance().getBoolean(Constants.LOGIN2)){
            ARouter.getInstance().build(RouterActivityPath.Main.PAGER_MAIN).navigation();
            finish();
        }*/
    }

    @Override
    public void initViewObservable() {
        //监听ViewModel中pSwitchObservable的变化, 当ViewModel中执行【uc.pSwitchObservable.set(!uc.pSwitchObservable.get());】时会回调该方法
        viewModel.uc.pSwitchEvent.observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(@Nullable Boolean aBoolean) {
                //pSwitchObservable是boolean类型的观察者,所以可以直接使用它的值改变密码开关的图标
                if (viewModel.uc.pSwitchEvent.getValue()) {
                    //密码可见
                    //在xml中定义id后,使用binding可以直接拿到这个view的引用,不再需要findViewById去找控件了
                    binding.tv.setTextSize(20);
                    binding.tv.setTypeface(Typeface.DEFAULT_BOLD);
                    binding.tv2.setTypeface(Typeface.DEFAULT);
                    binding.tv2.setTextSize(18);
                } else {
                    //密码不可见
                    binding.tv2.setTextSize(20);
                    binding.tv.setTextSize(18);
                    binding.tv2.setTypeface(Typeface.DEFAULT_BOLD);
                    binding.tv.setTypeface(Typeface.DEFAULT);
                }
            }
        });
    }
}
